<template>
  <el-dialog :title="dataForm.state?(!dataForm.id ? $t('Common.Add') : $t('Common.Edit')):'查看'" :close-on-click-modal="false" :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">

      <el-form-item v-show="dataForm.id" label="订单号" prop="payNumber">
        <el-tag>{{dataForm.payNumber}}</el-tag>
      </el-form-item>
      <el-form-item v-show="dataForm.id" label="时间" prop="creatTime">
        <el-tag>{{dataForm.creatTime}}</el-tag>
      </el-form-item>
<!--      <el-form-item label="支付" prop="payTime">
        <el-tag>{{dataForm.payTime}}</el-tag>
      </el-form-item> -->
      <el-form-item label="规格" prop="money">
        <template slot-scope="scope">
          <span>
            <el-tag>{{dataForm.counts}}条/{{dataForm.money}}元</el-tag>
          </span>
        </template>
      </el-form-item>
      <el-form-item label="实付" prop="payMoney">
        <el-input v-model="dataForm.payMoney" placeholder="实付金额"></el-input>
      </el-form-item>
      <el-form-item label="状态" prop="state" >
        <el-radio-group v-model="dataForm.state">
          <el-radio v-model="dataForm.state" :label="1">未支付</el-radio>
          <el-radio v-model="dataForm.state" :label="0">关闭订单</el-radio>
          <el-radio v-model="dataForm.state" :label="2">支付成功</el-radio>
          <el-radio v-model="dataForm.state" :label="3">支付失败</el-radio>
       </el-radio-group>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">{{dataForm.state==2?'返回':'取消'}} </el-button>
      <el-button type="primary" @click="dataFormSubmit()">{{ $t('Common.Confirm') }}</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data() {
      return {
        visible: false,
        dataForm: {
          id: 0,
          money: '',
          counts: '',
          creatTime: '',
          payNumber: '',
          sysUserId: '',
          state: 1,
          payType: '',
          payTime: '',
          payMoney: ''
        },
        dataRule: {
          payMoney: [{
            required: true,
            message: '实际支付金额不能为空',
            trigger: 'blur'
          }],
          state: [{
            required: true,
            message: '状态不能为空',
            trigger: 'blur'
          }]
        }
      }
    },
    methods: {
      init(id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/hotel/thotelsmspayorder/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({
              data
            }) => {
              if (data && data.code === 0) {
                this.dataForm.money = data.tHotelSmsPayOrder.money
                this.dataForm.payMoney = data.tHotelSmsPayOrder.payMoney
                this.dataForm.counts = data.tHotelSmsPayOrder.counts
                this.dataForm.creatTime = data.tHotelSmsPayOrder.creatTime
                this.dataForm.payNumber = data.tHotelSmsPayOrder.payNumber
                this.dataForm.sysUserId = data.tHotelSmsPayOrder.sysUserId
                this.dataForm.state = data.tHotelSmsPayOrder.state
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit() {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/hotel/thotelsmspayorder/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'money': this.dataForm.money,
                'payMoney': this.dataForm.payMoney,
                'counts': this.dataForm.counts,
                'creatTime': this.dataForm.creatTime,
                'payNumber': this.dataForm.payNumber,
                'sysUserId': this.dataForm.sysUserId,
                'state': this.dataForm.state
              })
            }).then(({
              data
            }) => {
              if (data && data.code === 0) {
                this.$message({
                  message: this.$t('Common.OperationSuccessful'),
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
